package judesart.app.server;

import java.util.List;

import javax.inject.Inject;

import judesart.app.domain.Artist;
import judesart.app.domain.Artwork;
import judesart.app.domain.ArtworkPhoto;
import judesart.app.domain.User;
import judesart.app.repository.ArtistDAO;
import judesart.app.repository.ArtworkDAO;
import judesart.app.repository.UserDAO;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/feeds")
public class FeedsController {

    @Inject
    private UserDAO userDAO;

    @Inject
    private ArtworkDAO artworkDAO;

    @Inject
    private ArtistDAO artistDAO;

    @RequestMapping(value = "/artworks.rss", method = RequestMethod.GET)
    @Transactional(propagation = Propagation.REQUIRED)
    public String artworks(Model model) {
        User user = userDAO.findFeatured();
        Artist artist = artistDAO.findArtistByUserId(user.getId());
        artist.getPhotos().get(0);
        List<Artwork> artworks = artworkDAO.findArtworks(artist.getId(), 0, 200, null, true);
        for (Artwork artwork : artworks) {
            List<ArtworkPhoto> photos = artwork.getPhotos();
            for (ArtworkPhoto photo : photos) {
            }
        }
        model.addAttribute(user);
        model.addAttribute(artist);
        model.addAttribute(artworks);
        return "rssArtworksFeedView";
    }
}
